
/* 
@title: basketballgame
@description: Basketball Game is a simple, original game developed by Dheeraj Chintapalli. In this game, players navigate through levels, avoiding obstacles and enemies, while trying to reach designated goal points. It features various elements such as blocks, spikes, and a resurrection stone that could potentially alter the gameplay.
@author: de-y (Dheeraj Chintapalli)
@tags: []
@addedOn: 2023-10-19
*/

    /*
Welcome to Basketball Game, a random game that I made.
*/
const player = "p";
const wall = "w";
const background = "c";
const block = 'b';
const goal_point = 'x';
const spikes = "s";
const ghost_model = 'g';
const enemy = 'm';
const resurrection_stone = 'r';
setLegend(
  [ player, bitmap`
................
................
................
.....0000.......
....000000......
....002020......
....000000......
....002220......
.....0000.......
......00........
....000000......
.....0000.......
.....0000.......
.....0..0.......
.....0..0.......
.....0..0.......` ],
  [wall, bitmap`
0CCCC0C00CC0CCC0
C0CC0CC00CCC0C0C
CC00CCC00CCC00CC
CC00CCC00CCC00CC
CC000CC00CC0C0CC
C0CCC0C00C0CCC0C
0CCCCC0000CCCC0C
0000000000000000
0000000000000000
0CCCCC0000CC0CC0
C0CCC0C00C0C0C0C
C0CC0CC00CC0CC0C
CC00CCC00CC000CC
CC00CCC00C0CC0CC
C0C0CCC00C0C0C0C
0CCC0CC000CC0CC0`],
  [background, bitmap`
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111
1111111111111111`],
  [block, bitmap`
................
................
................
................
......00000.....
.....0990990....
....090909090...
....099000990...
....000000000...
....099000990...
....090909090...
.....0990990....
......00000.....
................
................
................`],
  [goal_point, bitmap`
................
................
................
......000.......
.....33033......
....3333333.....
...333...333....
...33.....33....
...33.....33....
...33.....33....
...33.....33....
....3333333.....
.....33333......
................
................
................`],
  [spikes,bitmap`
................
................
................
................
................
................
................
................
................
................
................
................
......0.........
.....010........
....01110.......
...0111110......`],
  [ghost_model,bitmap`
................
................
................
................
................
................
.....11111......
....1222221.....
....1202021.....
....1222221.....
....1222221.....
.....10001......
......212.......
................
................
................`],
  [enemy,bitmap`
.....000000.....
....00200200....
....00000000....
....02222220....
.....444444.....
....44444444....
...4444444444...
...4444444444...
...4444444444...
...4444444444...
...4444444444...
...4444444444...
....44444444....
.....444444.....
................
................`],
  [resurrection_stone, bitmap`
................
................
......00........
.....0330.......
....03CC30......
...03C44C30.....
...03C44C30.....
...03CD0C30.....
...03C0DC30.....
...03C44C30.....
...03C44C30.....
....03CC30......
.....0330.......
......00........
................
................`],
)

setSolids([ player, block, wall ])

setBackground(background)
let level = 0
const levels = [
  map`
wwwwwww
wwwwwww
..b...x
.......
.wwwwww
pwwwwww`,
  map`
wwwwwwww..w
ww.b......w
...wwwwww.w
.www......w
...w......w
w..w.wwww..
...w.......
..ww.wwwwww
w..wxwwww..
...w.......
pw.w..wwww.`,
  map`
ww.x
s...
.bs.
....
p...`,
  map`
..m..
.....
pb..x
..m..
.....`,
  map`
...x
....
mb..
rps.`,
  map`
....
....
.b..
.p..`,
]
const unknownLevels = [
  map`
wwwwww
w....x
w.b.w.
w.m...
wpm...
wwwwww`,
]

setMap(levels[level])

setPushables({ 
  [player]: [ block, player ] 
})

function Text(string,x,y,color) {
  clearText()
  addText(string, {x: x,y:y,color: color});
}

Text("WASD to move.",4,0,color`2`)

function onceMovedToExit() {
  // console.log("Stage 1 Completed.")
}
onInput("w", () => {
  getFirst(player).y -= 1
})
onInput("a", () => {
  getFirst(player).x -= 1
})
onInput("d", () => {
  getFirst(player).x += 1
})
onInput("s", () => {
  getFirst(player).y += 1
})
onInput("j",() => {
  setMap(levels[0])
  clearText()
  level = 0
  Text("WASD to move.",4,0,color`2`)
})
// onInput("k",() => {
//   level = 0
//   setMap(unknownLevels[0]);
// })
afterInput(() => {
  if (tilesWith(player, resurrection_stone).length == 1) {
    // console.log("Unknown Level.")
    setMap(unknownLevels[0]);
    Text("Level: ???",0,0,color`2`);
  }
})
afterInput(() => {
  // console.log("Stage Check")
  if (tilesWith(block,goal_point).length == 1) {
    // console.log('Alright. Stage is over. Moving on.')
    // console.log((levels[level + 1]))
    setMap(levels[level + 1])
    level = level + 1
    onceMovedToExit()
    Text("Level: " + level + ', microsoft',0,0,color`2`)
    
  }
  else {
    // console.log("Stage Check Failed, conditions not met.")
  }
  if (tilesWith(player, spikes).length == 1 || tilesWith(player,enemy).length == 1) {
      // console.log("Death 💀");
      Text("You died!\nPress J to \nrestart.",5,7,color`2` )
      var x = tilesWith(player)[0][0]['_x']
      var y = tilesWith(player)[0][0]['_x']
      // console.log(x,y)
      clearTile(tilesWith(player)[0][0]['_x'],tilesWith(player)[0][0]['_y'])
      addSprite(x,y,ghost_model)
  }

})
